package com.jxsd.edu.cn.struts2.daoImpl;

import java.util.List;

import com.jxsd.edu.cn.struts2.dao.LabelViewDao;
import com.jxsd.edu.cn.struts2.models.LabelView;
import com.jxsd.edu.cn.tools.Page;
import com.jxsd.edu.cn.tools.PageBean;
import com.jxsd.edu.cn.tools.ResultBean;
import com.jxsd.edu.cn.tools.ResultList;
import com.jxsd.edu.cn.tools.Template;

public class LabelViewDaoImpl implements LabelViewDao {

	@Override
	public List<LabelView> getLabelViews(String  userId) {
		List<LabelView>   list=null;
		ResultList<LabelView>   hander=new  ResultList<LabelView>();
		String   sql="select  labelId,userId,nickname,smallId,smallName   from  labelview   where  userId=?";
		Object[]  params={userId};
		try {
			list=hander.handler(sql, params, LabelView.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
	}

	
	//待改进
	@Override
	public void addLabel(LabelView label) {
		String  sql=" insert  into  label(userId,smallId)   "+
                    "select   ?,smallId  from  smallCatagory  where  smallName=?";
		Object[]  params={label.getUserId(),label.getSmallId()};
		Template  t=new  Template();
		t.update(sql, params);
	}

	@Override
	public void deleteLabel(String labelId) {
		String  sql="delete  from  label  where  labelId=?";
		Object[]  params={labelId};
		Template  t=new  Template();
		t.update(sql, params);	
	}

	@Override
	public LabelView getLabelView(String labelId) {
		LabelView   label=null;
		String  sql="select  labelId,userId,smallId,nickname,smallName  from  labelview  where  smallId=?";
		Object[]  params={labelId};
		ResultBean<LabelView>  hander=new  ResultBean<LabelView>();
		try {
			label=hander.handler(sql, params, LabelView.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return label;
	}

	@Override
	public Page<LabelView> getLabels(PageBean<LabelView> pagebean)
	{
		String  sql="select  smallID as  'smallId',smallName  from  smallcatagory  order  by  SmallId";
		Object[]  params={};
		Page<LabelView>  page=null;
		ResultList<LabelView>  hander=new  ResultList<LabelView>();
		try {
			page=hander.pageHandler(pagebean, sql, params, LabelView.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return page;
	}
}
